<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let student = {
            name:'rose',
            age:18,
            boyfriend:{
                name:'jack',
                age:20,
                mother:{
                    name:'jennie',
                    age:40
                }
            },
            school:undefined,
            study(){
                console.log('正在学习');
            }
        }
        function cloneDeep(obj){
            //判断 需要拷贝的数据是数组还是对象
            //如果是数组，创建的内容为数组
            let newObj = Array.isArray(obj) ? [] : {}
            for(let k in obj){
                if(typeof obj[k] === 'object'){
                    newObj[k] = cloneDeep(obj[k])
                }else{
                    newObj[k] = obj[k]
                }
            }
            return newObj
        }
        const stuCopy = cloneDeep(student)
        console.log(stuCopy);
        console.log(stuCopy === student);
        console.log(stuCopy.boyfriend === student.boyfriend);
    </script>
</body>
</html>